home
***
CD-ROM
|
disk
|
FTP
|
other
***
search
/
PC World Komputer 2010 April
/
PCWorld0410.iso
/
pluginy Firefox
/
1035
/
1035.xpi
/
chrome
/
1clickweather.jar
/
content
/
1clickweather
/
js
/
obs.js
< prev
next >
Wrap
Text File
|
2008-10-05
|
8KB
|
245 lines
// handle the obs data
function oObs(){
var Data = {};
var xmlRequest = null;
this.init = function(id, url){
this.id = id; // id of the object to associate with the xul interface
this.url = url; // where we get the data from
DumperTagProperties["OPTION"] = ['text','value','defaultSelected'];
}
// Update() is called periodically to update the data in the object
this.Update = function(){
/* track */
//alert("Update");
if(this.url){
if(!xmlRequest){
xmlRequest = new XMLRequest(this.url);
xmlRequest.setParser(this);
}
//alert("Update get");
xmlRequest.Get();
}else{
alert("Update no url");
DumperAlert(this);
}
}
// if there is an error from the XMLRequestNonBlocking call, call this method
this.parseError = function(errCode){
alert("this.ParseError()");
}
this.Dump = function(){
DumperAlert(this);
}
this.setTooltip = function(){
alert("setTooltip is called");
// first, we make a tooltip object
var _tooltip = document.createElement("tooltip");
_tooltip.setAttribute("id", this.id + "Tooltip"); // and give it an id
var ttOuterVbox = document.createElement("vbox");
_tooltip.appendChild(ttOuterVbox);
// now we make a pair of hboxs
var ttTopHbox = document.createElement("hbox");
ttOuterVbox.appendChild(ttTopHbox);
var ttBottomHbox = document.createElement("hbox");
ttOuterVbox.appendChild(ttBottomHbox);
// now we make a pair of vboxs
var ttTImageVbox = document.createElement("vbox");
ttTopHbox.appendChild(ttTImageVbox);
var ttTTextVbox = document.createElement("vbox");
ttTopHbox.appendChild(ttTTextVbox);
// the image goes in the first vbox
var ttimg = document.createElement("image");
ttimg.setAttribute("src", "chrome://1clickweather/skin/icons/wx/64x64/" + Data['icon'] + ".png");
ttimg.setAttribute("width", "64");
ttimg.setAttribute("height", "64");
ttTImageVbox.appendChild(ttimg);
// the labels for text data go in the second vbox
var ttl = document.createElement("label");
ttl.setAttribute("value", "As of: " + Data['lsup']);
ttl.setAttribute("class", "header");
ttTTextVbox.appendChild(ttl);
var ttl = document.createElement("label");
ttl.setAttribute("value", "req time: " + Data['tm']);
ttl.setAttribute("class", "header");
ttTTextVbox.appendChild(ttl);
var ttl = document.createElement("label");
ttl.setAttribute("value", "in " + Data['dnam']);
ttTTextVbox.appendChild(ttl);
var ttl = document.createElement("label");
ttl.setAttribute("value", "");
ttTTextVbox.appendChild(ttl);
var ttl = document.createElement("label");
ttl.setAttribute("value", Data['t']);
ttTTextVbox.appendChild(ttl);
var ttl = document.createElement("label");
ttl.setAttribute("value", "Temperature: " + Data['tmp'] + " F");
ttTTextVbox.appendChild(ttl);
var ttl = document.createElement("label");
ttl.setAttribute("value", "Dew Point: " + Data['dewp'] + " F");
ttTTextVbox.appendChild(ttl);
var ttl = document.createElement("label");
ttl.setAttribute("value", "Humidity: " + Data['hmid'] + "%");
ttTTextVbox.appendChild(ttl);
var ttl = document.createElement("label");
ttl.setAttribute("value", "Visibility: " + Data['vis'] + " mi");
ttTTextVbox.appendChild(ttl);
var ttl = document.createElement("label");
ttl.setAttribute("value", "Pressure: " + Data['bar.r'] + " in and " + Data['bar.d']);
ttTTextVbox.appendChild(ttl);
var ttl = document.createElement("label");
ttl.setAttribute("value", "Wind out of the " + Data['wind.t'] + " at " + Data['wind.s'] + " mph");
ttTTextVbox.appendChild(ttl);
var ttl = document.createElement("label");
ttl.setAttribute("value", "");
ttTTextVbox.appendChild(ttl);
// now we make a pair of vboxs
var ttBImageVbox = document.createElement("vbox");
ttBottomHbox.appendChild(ttBImageVbox);
var ttBTextVbox = document.createElement("vbox");
ttBottomHbox.appendChild(ttBTextVbox);
// the image goes in the first vbox
var ttimg = document.createElement("image");
ttimg.setAttribute("src", "chrome://1clickweather/skin/icons/wx/64x64/" + Data['moon.icon'] +".png");
ttimg.setAttribute("width", "64");
ttimg.setAttribute("height", "64");
ttBImageVbox.appendChild(ttimg);
// the labels for text data go in the second vbox
var ttl = document.createElement("label");
ttl.setAttribute("value", "Tonight:");
ttl.setAttribute("class", "header");
ttBTextVbox.appendChild(ttl);
var ttl = document.createElement("label");
ttl.setAttribute("value", "Sunset: " + Data['suns']);
ttBTextVbox.appendChild(ttl);
var ttl = document.createElement("label");
ttl.setAttribute("value", "Moon Phase: " + Data['moon.t']);
ttBTextVbox.appendChild(ttl);
_tooltip.setAttribute("noautohide", false);
_tooltip.setAttribute("position", "before_start");
_tooltip.position = "overlap";
try{
document.getElementById("statusbar-currentconditions").removeChild(document.getElementById(this.id + "Tooltip"));
}
catch(e){
}
document.getElementById("statusbar-currentconditions").appendChild(_tooltip);
alert("done with tooltip");
}
// parse an xml doc into our obs object
this.parseFunc = function(xmlDoc){
Data = {}; // flush the Data hash
//alert("parser");
// first, we need to get the sunset since it's not in the cc node
try{
var xml_dnam = xmlDoc.getElementsByTagName('dnam')[0].firstChild.nodeValue;
if(xml_dnam){
Data['dnam'] = xml_dnam;
}
}
catch(e){
alert('dnam alert: ' + e.message);
}
// first, we need to get the sunset since it's not in the cc node
try{
var xml_suns = xmlDoc.getElementsByTagName('suns')[0].firstChild.nodeValue;
if(xml_suns){
Data['suns'] = xml_suns;
}
}
catch(e){
alert('suns alert: ' + e.message);
}
// first, we need to get the sunset since it's not in the cc node
try{
var xml_tm = xmlDoc.getElementsByTagName('tm')[0].firstChild.nodeValue;
if(xml_tm){
Data['tm'] = xml_tm;
}
}
catch(e){
alert('tm alert: ' + e.message);
}
// now we move on to the current conditions
var cc = xmlDoc.getElementsByTagName("cc")[0].childNodes;
var x = 0;
// loop through all the children under the cc node
for(x = 0; x < cc.length; x++){
try{
// if the nodes we find only have a value and no children, make them into variables
if((cc[x].childNodes.length == 1) && (typeof(cc[x].firstChild.nodeValue) == "string")){
Data[cc[x].nodeName] = cc[x].firstChild.nodeValue;
}else if(cc[x].childNodes.length > 1){
// if the child has more than one node under it, we deal with it a bit differently.
// we assume there will only be one more level below the current children so
// now we will make keys in Data[] names after the topchild.bottomchild like 'bar.r'
var child = cc[x].childNodes;
var y = 0;
for(y = 0; y < child.length; y++){
// if this is not a valid node name, skip it
if(child[y].nodeName == "#text"){
continue;
}
// otherwise, make a new entry in Data for it
if(typeof(child[y].firstChild.nodeValue) == "string"){
Data[cc[x].nodeName + "." + child[y].nodeName] = child[y].firstChild.nodeValue;
}
}
}
}
catch(e){
// alert(e.message);
}
}
//alert("done parsing");
//DumperAlert(Data);
this.setTooltip();
}
}